export default class ReqConfig {
	constructor() {
		this.safeCode = [200, 405]; //安全的code   正常数据的code
	};
	// 后端返回数据 code filter
	resCodeFilter(stateCode, allData) {
		if (allData) {
			this.safeCode.indexOf(parseInt(stateCode)) >= 0 ? '' : () => {
				uni.setClipboardData({
					data: allData
				});
				uni.showModal({
					content: '已将错误信息复制到剪贴版，请将其发送给程序猿',
					showCancel: false
				})
			}
		}

		return new Promise(resolve => {
			switch (stateCode) {
				case 405:
					code405();
					break;
				case 2000:
					code2000();
					break;
			}
			resolve();

			function code405() {
				// uni.showModal({
				// 	content: "您还未登录/登录过期，请登录之后再进行操作",
				// 	success: (response) => {
				// 		if (response.confirm) {
				// 			uni.switchTab({
				// 				url: "/pages/tabber/my",
				// 			})
				// 		}
				// 	},
				// });
				resolve('noLogin');
			}

			function code2000() {
				let user = uni.getStorageSync('userInfo');
				user.token = allData.response;
				uni.setStorageSync('userInfo', user);
				// token重置
				resolve('Rollback')
			}
		})
	};
	// 系统code filter
	systemCodeFilter(stateCode) {
		let isErr = false;
		return new Promise(resolve => {
			switch (stateCode) {
				case 404:
					code404();
					isErr = true;
					break;
				case 500:
					code500();
					isErr = true;
					break;
			}
			resolve(isErr);

			function code500() {
				uni.showToast({
					title: "服务端错误❌!",
					icon: "none",
					duration: 2000
				})
			};

			function code404() {
				uni.showToast({
					title: "404,页面走丢了~😁",
					icon: "none",
					duration: 2000
				})
			}
		})
	};

}